package com.example.droolstool.service;

import com.example.droolstool.module.TaxiFare;
import com.example.droolstool.module.TaxiRide;
import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 *
 * @Author 赵云龙
 * @Date 2020/6/6
 * @Description TODO
 */

@Service
public class TaxiFareCalculateService {

    public BigDecimal calculatorFare(TaxiRide taxiRide, TaxiFare taxiFare) {
        KieServices kieServices = KieServices.get();
        KieContainer kieContainer = kieServices.getKieClasspathContainer();
        KieSession kieSession = kieContainer.newKieSession("taxi-fare");
        kieSession.setGlobal("rideFare", taxiFare);
        kieSession.insert(taxiRide);
        kieSession.fireAllRules();
        kieSession.dispose();
        return taxiFare.total();
    }
}
